<template>
  <h2>Child子级组件</h2>
  <h3>{{msg}}</h3>
  <button @click="emitXxx">分发事件</button>
</template>

<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
  name:"Child",
  props:['msg'],

  setup(props, context) {
  //也可以写成
  //setup(props, {attrs, slots, emit}) {
     console.log(props, context);
     console.log(props.msg);
     console.log(context.attrs.msg2);
    //console.log("setup执行了",this);

    function emitXxx() {
      context.emit('xxx','++');
      //写成setup(props, {attrs, slots, emit}) 直接emit('xxx','++');
    }
    return {
      emitXxx
    }
  }
})
</script>

<style lang="scss" scoped>

</style>